import { loginApi } from '@/api/login'

const TOKEN = 'token-2022-01-06'

const state = {
  token: localStorage.getItem(TOKEN) || '',
  user: {}
}
const mutations = {
  set_Token(state, data) {
    state.token = data
  },
  set_UserInfo(state, data) {
    state.user = data
  }
}
const actions = {
  async LOGIN(store, formData) {
    const { data: { jwt, user }} = await loginApi(formData)
    // console.log(20, data)
    // return
    store.commit('set_Token', jwt)
    localStorage.setItem(TOKEN, jwt)
    store.commit('set_UserInfo', user)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
